﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Team4.rooms
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BLL.Security.PageSecurityAdminOnly(this);
        }

        protected void addRoomButton_OnClick(object sender, EventArgs e)
        {
            string roomName = roomNameTextBox.Text;
            string roomNumber = roomNumberTextBox.Text;

            // If nothing is entered do not create a room.
            if (string.IsNullOrWhiteSpace(roomName) || string.IsNullOrWhiteSpace(roomNumber)) return;

            // Create a new room.
            BLL.Room.CreateRoom(new BLL.Room() 
                                { 
                                    Id = -1,
                                    Name = roomName,
                                    Number = roomNumber 
                                });

            // Refresh grid view with new room.
            RoomObjectDataSource.DataBind();
            RoomGridView.DataBind();

            // Clear text boxes.
            roomNameTextBox.Text = string.Empty;
            roomNumberTextBox.Text = string.Empty;
        }
    }
}